<%@Page Language="VB"%>
<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.SqlClient" %>
<html><head>
<title>
The .NET DataSet and 
SqlDataAdapter Objects</title>
</head>
<body>
<span class="heading">DataTable and DataView Objects</span>
<hr width="350" align="left"/>
<div id="outError" runat="server">&nbsp;</div>
<br />
DataRelation Object<br />
<asp:datagrid id="dgrResult"	 
AutoGenerateColumns="False" runat="server" > 
<Columns> 
<asp:TemplateColumn HeaderText="CateName"> 
<ItemTemplate> 
<asp:Label ID="CateName" _
Text='<%# DataBinder.Eval(Container.DataItem, _
"SubCateName").toString()%>' 
Runat=server /> 
</ItemTemplate> </asp:TemplateColumn>
 <asp:TemplateColumn HeaderText="ItemName"> 
<ItemTemplate> 
<asp:Label ID="ItemName" _
Text='<%# DataBinder.Eval(Container.DataItem, _
"ItemName").toString()%>' 
Runat=server /> 
</ItemTemplate> </asp:TemplateColumn>
 </Columns> </asp:DataGrid> 
<br />
<script language="vb" runat="server">
Dim myDataSet As New DataSet()
Dim myDataView As DataView
Dim strSQL As String
Sub Page_Load(ByVal sender As Object, _
ByVal e As EventArgs)       
   Try
      Dim strConn As String
      strConn= _
      ConfigurationSettings.appSettings("conn")
      Dim myConn As New SqlConnection(strConn)      
      strSQL = "SELECT SubCateID, SubCateName  "
      strSQL +=" From tblSubCategories"
      strSQL +=" where SubCateID>10"
      Dim myDataAdapter As SqlDataAdapter
      myDataAdapter= New SqlDataAdapter(strSQL, myConn)
      myDataAdapter.Fill(myDataSet, "tblSubCategories")
      strSQL = "SELECT ItemID,ItemName,SubCateID "
      strSQL +=" From tblItems"
      strSQL +=" where SubCateID>10"
      myDataAdapter = New SqlDataAdapter(strSQL, myConn)
      myDataAdapter.Fill(myDataSet,  "tblItems")          
   Catch objError As Exception
      	outError.innerHTML = _
	"<b>* Error while " & _
	"accessing data</b>.<br />" & _
          	objError.Message & "<br />" & _
	objError.Source
      Exit Sub  
   End Try     
   MakeRelation()  
   MakeView()  
   dgrResult.DataSource = myDataView
   dgrResult.DataBind()   
End Sub
Private Sub MakeRelation()  
      Dim parentCol As DataColumn
      Dim childCol As DataColumn   
      parentCol = myDataSet.Tables("tblSubCategories").Columns("SubCateID")
      childCol = myDataSet.Tables("tblItems").Columns("SubCateID")
      Dim relCateItem As DataRelation
      relCateItem = New DataRelation("tblSubCategoriestblItems", parentCol, childCol)   
      myDataSet.Relations.Add(relCateItem)
End Sub

</script>
</body>
</html>
  